package main

import (
	"encoding/json"
	"fmt"
)

type Cat struct {
	Name  string
	Age   int
	Color string
	Hobby string
}

func (cat *Cat) say() string {

	infoStr := fmt.Sprintf("Name=[%v] age=[%v] color=[%v] hobby=[%v]",
		cat.Name, cat.Age, cat.Color, cat.Hobby)
	return infoStr
}

func main() {

	var cat1 Cat

	cat1.Name = "小白"
	cat1.Age = 3
	cat1.Color = "白色"
	cat1.Hobby = "吃饭睡觉打豆豆"

	fmt.Println(cat1)

	fmt.Println("猫猫得信息如下：")

	fmt.Println("name=", cat1.Name)
	fmt.Println("age=", cat1.Age)
	fmt.Println("color=", cat1.Color)
	fmt.Println("hobby=", cat1.Hobby)

	jsonStr, err := json.Marshal(cat1)
	if err != nil {
		fmt.Println("json处理失败", err)
	}

	fmt.Println("jsonStr", string(jsonStr))

	var ca = Cat{"张三", 18, "蓝色", "拆家"}
	result := ca.say()
	fmt.Println(result)
}
